package com.quanquan.store.repository.marketActivity.paperPlane;

import com.quanquan.store.entity.marketActivity.paperPlane.PaperPlaneCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName PaperPlaneCodeRepository
 * @Description
 * @Author Owen
 * @Date 2019/9/17 0017 下午 2:30
 * @Version V1.0
 **/
public interface PaperPlaneCodeRepository extends JpaRepository<PaperPlaneCode,Integer>, JpaSpecificationExecutor<PaperPlaneCode> {

    PaperPlaneCode findByCodeAndActivityId(String code, Long activityId);

    @Query(value = "select count(distinct(user_id)) from oo_paper_plane_code where activity_id=?1 and status >= ?2",nativeQuery = true)
    int countByStatus(Long activityId, int status);

    @Query(value = "select distinct(user_id) from oo_paper_plane_code where activity_id=?1 and status =2 and difficulty=?2",nativeQuery = true)
    List<String> findByDifficulty(Long activityId, Integer difficulty);
}
